// Copyright (c) [Year] [name of copyright holder]
// [Software Name] is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2. 
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2 
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
// See the Mulan PSL v2 for more details.

/*!
 * \autor captainpeng
 * \date 2019-9-9
 * \update 2019-9-9
 * \version 1.0
 * \copyright
 */

#ifndef MY_ASSUER_HPP
#define MY_ASSUER_HPP

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include"typeLib.hpp"

namespace my{

    inline void assure(bool flag, const std::string & str = "my::assure(): error"){
        if(!flag){
            std::cerr<<str<<std::endl;
            exit(1);
        }
    }
    
    template<typename ... Args>
    inline void assure(bool flag, const std::string & fmt, Args ... args){
        static_assert(typeOp<
                      char, const char, char *, const char *,
                      unsigned char, const unsigned char,  char *, const unsigned char *,
                      wchar_t, const wchar_t, wchar_t *, const wchar_t *,
                      short, const short, unsigned short, const unsigned short, short *,
                      int , const int, unsigned int, const unsigned int, int *,
                      long, const long, unsigned long, const unsigned long, long *,
                      long long, const long long, unsigned long long, const unsigned long long, long long *,
                      double, const double,
                      size_t, const size_t >
                      ::func_include<Args ...>::value, "my::assure, 请输入符合格式正确的类型");
                                  
        if(!flag){
            char buf[2048];
            std::snprintf(buf, 2048, fmt.c_str(), args...);
            std::cerr<<buf<<std::endl;
            exit(1);
        }
    }

    template<typename ... Args>
    inline void errExit(bool flag, const std::string & fmt, Args ... args){
        if(flag) return ;
        std::string fmt1(fmt + ", %s");
        assure(flag, fmt1, args..., std::strerror(errno));
    }
}

#endif
